package com.jwthhealth_pub.wristband.view.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.jwthhealth_pub.R;
import com.jwthhealth_pub.wristband.view.SportStatisticsActivity;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * home msg adapter
 * Created by yang on 2017/12/26.
 */

public class SportListAdapter extends RecyclerView.Adapter {

    private Context mContext;

    public SportListAdapter(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {


        if (viewType == SportListAdapter.MsgType.MSG.ordinal())
            return new SportListAdapter.ViewHolder(View.inflate(mContext, R.layout.item_sport_list, null));
        else if (viewType == SportListAdapter.MsgType.SUBSCRIBE.ordinal())
            return new SportListAdapter.ViewHolder(View.inflate(mContext, R.layout.item_sport_list, null));
        else
            return new SportListAdapter.ViewHolder(View.inflate(mContext, R.layout.item_sport_list, null));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final SportListAdapter.ViewHolder vh = (SportListAdapter.ViewHolder) holder;

        vh.ll_item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, SportStatisticsActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        // TODO: 2017/12/6 3
        return 4;
    }

    @Override
    public int getItemViewType(int position) {
        if (position == 0)
            return MsgType.MSG.ordinal();
        else if (position == 1)
            return MsgType.SUBSCRIBE.ordinal();
        else
            return MsgType.ORDER.ordinal();
    }

     class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.ll_item)
        LinearLayout ll_item;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    private enum MsgType {
        MSG, ORDER, SUBSCRIBE
    }
}
